package com.tesis_2.DA;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.tesis_2.MO.MOLocal;
import com.tesis_2.MO.MOPlato;

public class DAOPlatos {

	
	public static ArrayList<MOPlato> getPlatos() throws JSONException {
		//DAORestaurants.lsRest = lsRest;
		
		ArrayList<MOPlato> lsPlatos = new ArrayList<MOPlato>();
		
	    try{

	    	JSONArray platos = (new JSONReaderArray().execute(DAOUtils.getServer()+ "/dishes.json")).get();
	    	
	    	if (platos == null) return lsPlatos;
	       	    	
	    	for (int i = 0; i < platos.length(); i++) {
	    		JSONObject jsonPlatos = platos.getJSONObject(i);
	    	    jsonPlatos = jsonPlatos.getJSONObject("dish");
	    	    //obtengo el restaurante
	    	    MOPlato objPlato = new MOPlato();
	    	    //entro al objeto y leo los atributos
	    	    
	    	    objPlato.setCost((float)jsonPlatos.getDouble("cost"));
	    	    objPlato.setCreated_at(DAOUtils.parseDateIso(jsonPlatos.getString("created_at")));
	    	    objPlato.setDescr(jsonPlatos.getString("descr"));
	    	    objPlato.setId(jsonPlatos.getInt("id"));
	    	    objPlato.setName(jsonPlatos.getString("name"));
	    	    objPlato.setRestaurant_id(jsonPlatos.getInt("restaurant_id"));
	    	    objPlato.setStatus(jsonPlatos.getInt("status"));
	    	    objPlato.setUpdated_at(DAOUtils.parseDateIso(jsonPlatos.getString("updated_at")));
	    	    objPlato.setRate((float)jsonPlatos.getDouble("rate"));
	    	    lsPlatos.add(objPlato);
	    	}
	 
	    }catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return lsPlatos;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return lsPlatos;
		}
		return lsPlatos;
		
	}
	
}
